package org.xx.armory.spring5.jdbc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.xx.armory.commons.ForLogging;
import org.xx.armory.spring5.junit.H2DbUnitHelper;
import org.xx.armory.spring5.junit.OracleDbUnitHelper;

import javax.sql.DataSource;

/**
 * JDBC测试相关的Bean配置。
 */
@SpringBootConfiguration
@EnableTransactionManagement
@EnableAutoConfiguration(exclude = {HibernateJpaAutoConfiguration.class})
@ComponentScan(basePackages = {"org.xx.armory.spring5.jdbc"})
public class Config {
    @ForLogging
    private final Logger logger = LoggerFactory.getLogger(Config.class);

    @Bean
    public PlatformTransactionManager transactionManager(
            DataSource dataSource
    ) {
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public H2DbUnitHelper h2DbUnitHelper() {
        return new H2DbUnitHelper();
    }

    @Bean
    public OracleDbUnitHelper oracleDbUnitHelper() {
        return new OracleDbUnitHelper();
    }
}
